<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.thymeleaf.org/thymeleaf-extras-shiro"
>
<head>
    <meta charset="UTF-8">
    <title>人员管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/resources/css/public.css" media="all"/>
    <!-- 引入 layui.css -->
    <link rel="stylesheet" href="//unpkg.com/layui@2.6.8/dist/css/layui.css">

    <!-- 引入 layui.js -->
    <script src="//unpkg.com/layui@2.6.8/dist/layui.js"></script>
    <style>
        input#search_provideridTree_select_input_id {
            border-radius: 10px;
            height: 30px;
            margin-top: 4px;
        }
        input#provideridTree_select_input_id {
            border-radius: 10px;
            height: 30px;
            margin-top: 4px;
        }
        input#leaderprovideridTree_select_input_id {
            border-radius: 10px;
            height: 30px;
            margin-top: 4px;
        }
        input.layui-input.layui-unselect {
            border-radius: 10px;
            height: 30px;
            margin-top: 4px;
        }
    </style>
    <style>
        .layui-table-cell{
            height:50px;
            line-height: 50px;
        }
    </style>
</head>
<body  class="childrenBody">
<!--查询条件开始-->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>文件数据管理</legend>
</fieldset>
<blockquote class="layui-elem-quote">
    <form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form">

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="goodsname" id="goodsname" class="layui-input input-radius"
                           placeholder="请输入姓名">
                </div>
            </div>

            <div class="layui-inline" style="padding-left: 3%">
                <button type="button" class="layui-btn layui-btn-sm layui-btn-radius" lay-submit="" lay-filter="doSearch"><i
                        class="layui-icon layui-icon-search layui-icon-normal"></i>查询
                </button>
                <button type="reset" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-warm"><i
                        class="layui-icon layui-icon-refresh"></i><span>重置</span>
                </button>
            </div>
        </div>
    </form>
</blockquote>
<!--查询条件结束-->

<!--分页表格开始-->
<table class="layui-hide" id="goodsTable" lay-filter="goodsTable"></table>
<div id="goodsToolBar" style="display: none">
    <button type="button" lay-event="add" shiro:hasPermission="goods:create" class="layui-btn layui-btn-sm layui-btn-normal layui-btn-radius">
        <i class="layui-icon layui-icon-add-1"></i>添加人员
    </button>
    <button type="button" lay-event="batchDelete"    class="layui-btn layui-btn-sm layui-btn-danger layui-btn-radius"  shiro:hasPermission="goods:batchdelete">
        <i class="layui-icon layui-icon-delete"></i>批量删除
    </button>
    <button type="file" class="layui-btn layui-btn-sm layui-btn-radius" id="test1"
            lay-data="{accept: 'file'}">
        <i class="layui-icon">&#xe67c;</i>上传文件
    </button>
</div>
<div id="goodsRowBar" style="display: none;">
    <button type="button" lay-event="update"  class="layui-btn layui-btn-sm layui-btn-radius"><i
            class="layui-icon layui-icon-edit" shiro:haspermission="goods:update"></i>编辑
    </button>
    <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger layui-btn-radius"><i
            class="layui-icon layui-icon-delete" shiro:haspermission="goods:delete"></i>删除
    </button>
</div>
</div>
<!--分页表格结束-->
<!--添加和修改数据表格开始-->
<div id="addOrUpdateDiv" style="display: none;padding: 10px;padding-right: 5%">
    <form action="" method="post" class="layui-form" id="dataFrm" lay-filter="dataFrm">
        <div class="layui-col-md12 layui-col-xs12">
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md9 layui-col-xs7">

                    <div class="layui-form-item">
                        <label class="layui-form-label">姓名</label>
                        <div class="layui-input-block">
                            <input type="hidden" name="id">
                            <input type="text" class="layui-input input-radius" name="goodsname" lay-verify="required" placeholder="请输入姓名">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">身份证号</label>
                        <div class="layui-input-block">
                            <input type="hidden" name="id">
                            <input type="text" class="layui-input input-radius" name="goodsname" lay-verify="required" placeholder="请输入姓名">
                        </div>
                    </div>

                </div>
            </div>
            <div class="layui-form-item magb0">
                <div class="layui-inline">
                    <label class="layui-form-label">年龄</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input input-radius" name="goodspackage" lay-verify="required" placeholder="请输入年龄">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="available" value="1" title="男" checked="">
                        <input type="radio" name="available" value="0" title="女" >
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input input-radius" name="size" lay-verify="required" placeholder="请输入手机号">
                    </div>
                </div>


                <div class="layui-inline">
                    <label class="layui-form-label">是否已经接种新冠疫苗</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="available" value="1" title="是" checked="">
                        <input type="radio" name="available" value="0" title="否" >
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">接种针次</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input input-radius" name="size" lay-verify="required" placeholder="请输入接种针次">
                    </div>
                </div>

            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;padding-right: 7%">
                <button type="button" class="layui-btn layui-btn-radius" lay-submit="" lay-filter="doSubmit" id="doSubmit"><i
                        class="layui-icon layui-icon-search layui-icon-normal"></i>提交
                </button>
                <button type="reset" class="layui-btn layui-btn-radius layui-btn-warm"><i
                        class="layui-icon layui-icon-refresh"></i><span>重置</span>
                </button>
            </div>
        </div>
    </form>

</div>


<!--添加和修改数据表格结束-->

<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['jquery', 'form', 'layer', 'laydate', 'table','layedit','upload'], function () {
        var $ = layui.jquery;
        var form=layui.form;
        var layer = layui.layer;
        var table = layui.table;
        var layedit=layui.layedit;
        var upload=layui.upload;
        //打开添加页面
        var mainIndex;
        var type;
        //初始化表格
        var tableIns = table.render({
            elem: "#goodsTable",
            title: "日志数据表格",
            url: "/userInfo/loadAllData",
            toolbar: "#goodsToolBar",
            page: true,
            height: "full-100",
            cols: [ [
                {field: 'id', title: 'ID', align: 'center',width:'50',hide: true},
                {field: 'userName', title: '姓名', align: 'center',width:'150'},
                {field: 'gender', title: '性别', align: 'center',width:'150'},
                {field: 'age', title: '年龄', align: 'center',width:'150'},
                {field: 'idCardNum', title: '身份证号', align: 'center',width:'251'},
                {field: 'telNum', title: '手机号', align: 'center',width:'150'},
                {field: 'isVac', title: '是否接种新冠疫苗', align: 'center',width:'150',templet:function (d) {
                        return d.isVac=='1'?'<font color="blue">接种</font>':'<font color="red">未接种</font>';
                    }},
                {field: 'numOfVac', title: '接种针次', align: 'center',width:'100'},
                {fixed: 'right', title: '操作', toolbar: '#goodsRowBar', align: 'center',width:'300'}
            ] ],
            done:function (data, curr, count) {
                //不是第一页时，如果当前返回的数据为0那么就返回上一页
                if(data.data.length==0&&curr!=1){
                    tableIns.reload({
                        page:{
                            curr:curr-1
                        }
                    })
                }
                $("#total").html(count);
            }
        });
        //监控模糊查询按钮事件
        form.on("submit(doSearch)", function (data) {
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        //监控工具条事件
        //批量删除和添加
        table.on("toolbar(goodsTable)", function (obj) {
            switch (obj.event) {
                case 'add':
                    openAdd();
                    break;
                case 'batchDelete':
                    batchDelete();
                    break;


            };
        });

        //监控行工具条事件
        //查看，编辑，删除
        table.on("tool(goodsTable)",function (obj) {
            //获取当前行数据
            var data = obj.data;
            switch (obj.event){
                case 'show':
                    showgoods(data);
                    break;
                case 'update':
                    updategoods(data);
                    break;
                case 'delete':
                    deletegoods(data);
                    break;
            };
        });

        //打开添加的弹出层
        function openAdd() {
            mainIndex = layer.open({
                type:1,
                content:$("#addOrUpdateDiv"),
                area:['800px','550px'],
                title:'添加人员',
                success:function () {
                    $('#dataFrm')[0].reset();
                    type="POST";
                    $.ajax({
                        url: "/good/loadAllgoodsProviders",    //请求的URL地址
                        type: "GET", //请求方法，GET、POST、PUT、DELETE在这里设置
                        timeout: 5000,    //超时时间
                        dataType: 'json',
                        success: function (res) {    //成功的回调函数
                            var data=res.data;
                            var html='  <option value="0">请选择供应商</option>';
                            var dom=$("#providerid");
                            $.each(data,function (index,item) {
                                html+='  <option value='+item.id+'>'+item.providername+'</option>';
                            })
                            dom.html(html);
                            form.render("select")
                        }
                    })
                }
            });
        };
        //打开修改的弹出层
        function updategoods(data) {
            mainIndex = layer.open({
                type:1,
                content:$("#addOrUpdateDiv"),
                area:['800px','550px'],
                title:'修改人员信息',
                success:function () {
                    //装载新的数据
                    $('#dataFrm')[0].reset();
                    form.val("dataFrm",data);
                    $(".thumbImg").attr("src",'/file/showImageByPath?path='+data.goodsimg);
                    $.ajax({
                        url: "/good/loadAllgoodsProviders",    //请求的URL地址
                        type: "GET", //请求方法，GET、POST、PUT、DELETE在这里设置
                        timeout: 5000,    //超时时间
                        dataType: 'json',
                        success: function (res) {    //成功的回调函数
                            var html='  <option value="0">请选择供应商</option>';
                            var dom=$("#providerid");
                            var resdata=res.data;
                            $.each(resdata,function (index,item) {
                                if (data.providerid===item.id)
                                {
                                    html+='  <option value='+item.id+'  selected>'+item.providername+'</option>';
                                }
                                else
                                {
                                    html+='  <option value='+item.id+'>'+item.providername+'</option>';
                                }

                            })
                            dom.html(html);
                            form.render("select")
                        }
                    })

                    //装载新的数据
                    type="PUT";
                }
            });
        };
        //提交修改和添加的弹出层数据
        $("#doSubmit").click(function () {
            //同步富文本和textarea里面的内容
            var datas = $("#dataFrm").serialize();
            $.ajax({
                url:"/good/goods",    //请求的URL地址
                type:type, //请求方法，GET、POST、PUT、DELETE在这里设置
                timeout:5000,    //超时时间
                dataType:'json',
                data:datas,
                //返回的数据格式：json/xml/html/script/jsonp/text
                success:function(data){    //成功的回调函数
                    if (data.code==200){
                        tableIns.reload();
                        layer.msg(data.msg) //设置id为result的标签的html内容为返回的data数据
                        layer.close(mainIndex);
                    }
                    else
                    {
                        layer.msg(data.msg) //设置id为result的标签的html内容为返回的data数据
                    }

                },

            })
        });
        //文件上传(重点代码在这里)
        upload.render({
            elem: '.thumbBox',
            url: '/file/uploadFile',
            acceptMime:'image/*',
            field:'mf',
            method : "post",
            done: function(res, index, upload){
                var path=res.path;
                $('.thumbImg').attr('src','/file/showImageByPath?path='+path);
                $('.thumbBox').css("background","#fff");
                //给隐藏域赋值
                $("#goodsimg").val(path);
            }
        });
        //文件上传（自己写）
        upload.render({
            elem: '#test1' //绑定元素
            ,url: '/userInfo/upload' //上传接口
            ,done: function(res){
                alert(res.msg);

                //上传完毕回调
            }
            ,error: function(){
                //请求异常回调
            }
        })

        //删除
        function deletegoods(data) {
            layer.confirm('你确定要删除这条数据吗？',{icon: 3,title:'提示'},function (index) {
                $.ajax({
                    url:"/good/goods",    //请求的URL地址
                    type:"DELETE", //请求方法，GET、POST、PUT、DELETE在这里设置
                    timeout:5000,    //超时时间
                    dataType:'json',
                    data:{id:data.id},
                    //返回的数据格式：json/xml/html/script/jsonp/text
                    success:function(res){    //成功的回调函数
                        if (res.code==200){
                            tableIns.reload({
                                where:"",
                            });
                            layer.msg(res.msg);
                        }

                    },

                })
                layer.close(index);
            });
        }
        //批量删除
        function batchDelete() {
            //得到选中行
            var checkStatus = table.checkStatus('goodsTable');
            var dataLength = checkStatus.data.length;
            if (dataLength>0){
                layer.confirm('你确定要删除这些数据吗？',{icon: 3,title: '提示'},function (index) {
                    //获取选中行数据
                    var data = checkStatus.data;
                    var ids = "";
                    $.each(data,function (index, item) {
                        if (index==0){
                            ids+="ids="+item.id;
                        }else {
                            ids+="&ids="+item.id;
                        }
                    });
                    $.post("/goods/batchDeletegoods",ids,function (res) {
                        if (res.code==200){
                            //重新刷新表格
                            tableIns.reload({
                                where:"",
                            });
                        }
                        layer.msg(res.msg);
                    });
                    layer.close(index);
                });
            }else {
                layer.msg("请选中操作行")
            }
        }

    });

</script>
</body>
<!--</html>-->
<!--<!DOCTYPE html>-->
<!--<html lang="en" xmlns:th="http://www.thymeleaf.org">-->
<!--<head>-->
<!--    <script type="text/javascript" th:src="@{https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js}"></script>-->
<!--    <link th:href="@{https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css}" rel="stylesheet"/>-->
<!--    <meta charset="UTF-8"/>-->
<!--    <title>疫苗接种情况</title>-->
<!--</head>-->

<!--<body>-->

<!--<div class="contentDiv">-->


<!--    <table class="table table-hover table-condensed">-->
<!--        <legend>-->
<!--            <strong>疫苗接种情况</strong>-->
<!--        </legend>-->
<!--        <div>-->
<!--            <label for="inputfile">文件上传</label>-->
<!--            <input type="file" id="inputfile">-->
<!--            <a class="btn btn-primary" href="/book/create" role="button">查询</a>-->
<!--        </div>-->
<!--        <thead>-->
<!--        <tr>-->
<!--            <th>编号</th>-->
<!--            <th>姓名</th>-->
<!--            <th>年龄</th>-->
<!--            <th>身份证号码</th>-->
<!--            <th>手机号</th>-->
<!--            <th>是否已接种疫苗</th>-->
<!--            <th>接种针次</th>-->
<!--        </tr>-->
<!--        </thead>-->
<!--        <tbody>-->
<!--        <tr th:each="user : ${userList}">-->
<!--            <th scope="row" th:text="${user.id}"></th>-->
<!--            <td><a th:href="@{/book/update/{bookId}(bookId=${user.id})}" th:text="${user.userName}"></a></td>-->
<!--            <td th:text="${user.age}"></td>-->
<!--            <td th:text="${user.idCardNum}"></td>-->
<!--            <td th:text="${user.telNum}"></td>-->
<!--            <td th:text="${user.isVac}"></td>-->
<!--            <td th:text="${user.numOfVac}"></td>-->
<!--            <td><a class="btn btn-danger" th:href="@{/book/delete/{bookId}(bookId=${user.id})}">删除</a></td>-->
<!--        </tr>-->
<!--        </tbody>-->
<!--    </table>-->
<!--</div>-->
<!--</body>-->
<!--</html>-->